#include "EpollServer.hpp"
#include <memory>

Response Calculate(const Request &rq)
{
    Response resp;
    memset(&resp, 0, sizeof(resp));
    switch (rq._op)
    {
    case '+':
        resp._result = rq._x + rq._y;
        break;
    case '-':
        resp._result = rq._x - rq._y;
        break;
    case '*':
        resp._result = rq._x * rq._y;
        break;
    case '/':
        if (rq._y == 0)
            resp._code = 1;
        else
            resp._result = rq._x / rq._y;
        break;
    case '%':
        if (rq._y == 0)
            resp._code = 2;
        else
            resp._result = rq._x % rq._y;
        break;
    default:
        resp._code = 3;
        break;
    }
    return resp;
}

int main(int args, char *argv[])
{
    // uint16_t port = atoi(argv[1]);
    std::unique_ptr<EpollServer> svr(new EpollServer(Calculate));
    svr->InitServer();
    svr->Dispatcher();

    return 0;
}